package com.woniuxy.merchant.controller;


import com.woniu.commons.util.TokenUtil;
import com.woniu.dto.ContactVO;
import com.woniu.zsd.commons.core.model.Result;
import com.woniuxy.merchant.entity.ChatMessage;
import com.woniuxy.merchant.service.IChatMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-13
 */
@RestController
@Api(tags = "聊天记录")
@RequestMapping("/chat-message")
@Api(tags = "聊天")
public class ChatMessageController {
    @Resource
    private IChatMessageService chatMessageService;
    @Resource
    private TokenUtil tokenUtil;

    @ApiOperation("用户查询聊天记录")
    @GetMapping("/query")
    public Result<List<ChatMessage>> queryChatHistory( @ApiParam(value = "发送用户id") @RequestHeader String token) {
        Integer userId = tokenUtil.getAdminId(token);
        return new Result<List<ChatMessage>>().setCode(200).setMsg("查询聊天记录成功").setData(chatMessageService.getChatHistory(userId));
    }
    @ApiOperation("用户查询聊天对象")
    @GetMapping("/query/toInfo")
    public Result<List<ContactVO>> queryToInfo(@ApiParam(value = "发送用户id") @RequestHeader String token) {
        Integer userId = tokenUtil.getAdminId(token);
        return new Result<List<ContactVO>>().setCode(200).setMsg("查询聊天对象信息成功").setData(chatMessageService.queryToInfo(userId));
    }


}
